import { BrowserWindow, screen } from 'electron'
import { join } from 'path'
import { is } from '@electron-toolkit/utils'

function createDeskTopWindow() {
  const width = 440
  const height = 80

  // 获取屏幕尺寸信息
  const { screen } = require('electron')
  const { width: screenWidth, height: screenHeight } = screen.getPrimaryDisplay().workAreaSize

  // 计算窗口右下角位置
  const x = screenWidth - width
  const y = screenHeight - height

  const mainWindow = new BrowserWindow({
    width: width,
    height: height,
    minHeight: height,
    minWidth: width,
    maxHeight: height,
    maxWidth: width,
    transparent: true,
    alwaysOnTop: true,
    frame: false,
    show: false,
    skipTaskbar: true, // 隐藏窗口不显示在任务栏
    webPreferences: {
      nodeIntegration: false,
      contextIsolation: true,
      preload: join(__dirname, '../preload/index.js'),
      sandbox: false
    },
    // 设置窗口初始位置为右下角
    x: x,
    y: y
  })

  if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
    mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
  } else {
    mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
  }
}


export { createDeskTopWindow }
